package swag.t;

import android.app.Activity;
import android.app.Service;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;
import android.view.View;
import android.widget.Button;

public class ServiceTestActivity extends Activity {
    /** Called when the activity is first created. */
  Service appService;
	
  Context myContext;
  
  private ServiceConnection onService = new ServiceConnection()
	{
		
	
  public void onServiceConnected(ComponentName className, IBinder rawBinder)
  
  {
  	appService = ((ServiceTest.LocalBinder) rawBinder).getService();
  	
  }
  
  public void onServiceDisconnect(ComponentName className)
  {
  	appService = null;
  }

	public void onServiceDisconnected(ComponentName name) {
		// TODO Auto-generated method stub
		
	}
	};
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        myContext = this;
        
        bindService(new Intent(this, ServiceTest.class), onService, Context.BIND_AUTO_CREATE); // you need tobind to a service before creating it 
        Button button1 =(Button) findViewById(R.id.button1);
        button1.setOnClickListener(new View.OnClickListener() {
        	public void onClick(View v) {
        System.out.println(appService);
        appService.startService(new Intent(myContext,ServiceTest.class));
        
        	}
        });
        
    }
	
	
}

	
